﻿using System;
using UnityEngine;

public class AnimController : MonoBehaviour
{

    private GameObject Player;
    private Transform PlayerTransform;
    private Animator anim;
    private RoleController roleController;

    public Action<Vector2> MoveAnimSenderAction;
    public Action<Vector2> MoveAnimGetterAction;

     
    //private void Awake()
    //{
    //    Init(rotateAxis);
    //}

    /// <summary>
    /// 初始化
    /// </summary>
    /// <param name="R_Axis"></param>
    public void Init(Animator anim,RoleController roleController)
    {
        this.anim = anim;
        this.roleController = roleController;
        print("添加手柄动画函数");
        if (roleController.info.isLocalPlayer)
        {
            ETCJoyUIController._instance.leftJoyStick.onMove.AddListener(TouchOnMove);
            ETCJoyUIController._instance.leftJoyStick.onMoveEnd.AddListener(OnTouchUp);
        }
        else
        {
            //非本地角色，监听服务器同步信息
            
        }
        print("添加手柄移动函数2");
    }

    /// <summary>
    /// 移动
    /// </summary>
    /// <param name="pos"></param>
    public void TouchOnMove(Vector2 pos)
    {
        //print("tan绝对值:"+JD_Tan);
        anim.SetFloat("MoveX", pos.x);
        anim.SetFloat("MoveY", pos.y);
        if (MoveAnimSenderAction!= null)
        {
            MoveAnimSenderAction(pos);
        }
        //同步动画给服务器，以id区分动画对象
    }

    

    /// <summary>
    /// 停止触摸后动画归零
    /// </summary>
    public void OnTouchUp()
    {
        anim.SetFloat("MoveX", 0);
        anim.SetFloat("MoveY", 0);
        if (MoveAnimSenderAction != null)
        {
            MoveAnimSenderAction(Vector2.zero);
        }
    }

    /// <summary>
    /// 初始化攻击速度
    /// </summary>
    public void SetActionSpeed()
    {

    }

    /// <summary>
    /// 跳击
    /// </summary>
    //public void PlayJump()
    //{
    //    anim.SetTrigger("JumpAttack");
    //    //短暂移动系数加速
    //    Tween temp = DOTween.To(() => moveSpeedRatio, x => moveSpeedRatio = x, 1.3f, 1.5f);
    //    temp.SetEase(Ease.InCirc);
    //}

}
